<template>
  <div>
    <FormPanel ref="form" :list="form" :cols="3" :labelWidth="100" formType="add" :isSubmitBtn="false" columnsRef="asdasdxkpjxscxTable" @formChange="searchAdjustOrderEdit"></FormPanel>

    <div class="confirm-button-style" style="text-align:center;margin-top:20px;">
      <el-button type="primary" :loading="addBtnLoading" @click="saveDialog">确 定</el-button>
      <el-button @click="closeDialog">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { updateInventoryNoData } from '@/api/part/partInventory/partOverflow';

import { notifyAction } from '@/utils';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'partOverflowAdd',
  mixins: [dictionary],
  props: {
    editData: Object
  },
  data() {
    return {
      form: this.createForm(),
      addBtnLoading: false
    };
  },
  created() {
    this.initData();
  },
  mounted() {},
  methods: {
    createForm() {
      return [
        {
          type: 'INPUT',
          label: '仓库',
          fieldName: 'store',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'partCode',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'partName',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          label: '报溢数量',
          fieldName: 'overflowNum'
          // placeholder: 1.00,
        },
        {
          type: 'INPUT',
          label: '报溢单价',
          fieldName: 'overflowPrice',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '报溢金额',
          fieldName: 'overflowAmount',
          disabled: true
        }
      ];
    },
    // 初始化数据
    initData() {
      let rowData = this.editData.row;
      this.form[0].initialValue = rowData.STORAGE_NAME;
      this.form[1].initialValue = rowData.PART_NO;
      this.form[2].initialValue = rowData.PART_NAME;
      this.form[3].initialValue = rowData.PROFIT_QUANTITY;
      this.form[4].initialValue = rowData.PROFIT_PRICE;
      this.form[5].initialValue = rowData.PROFIT_AMOUNT;
    },
    searchAdjustOrderEdit() {},
    // 点击确定
    async saveDialog() {
      let formData = await this.$refs.form.GET_FORM_DATA();
      let submitRowData = Object.assign(this.editData.row, { PROFIT_QUANTITY: formData[1].overflowNum });

      if (this.addBtnLoading) return;
      this.addBtnLoading = true;
      try {
        let res = await updateInventoryNoData({
          partProfitItemList: [submitRowData],
          profitNo: submitRowData.PROFIT_NO,
          inventoryNo: submitRowData.INVENTORY_NO,
          partProfitId: submitRowData.PART_PROFIT_ID
        });
        this.addBtnLoading = false;
        if (res.resultCode == 200) {
          notifyAction('修改成功');
          this.$emit('resetTableData');
          this.closeDialog();
        }
      } catch (err) {
        this.addBtnLoading = false;
        console.log(err);
      }
    },
    //  点击取消关闭窗口
    closeDialog() {
      this.$emit('close', false);
    }
  }
};
</script>
<style lang="less" scoped></style>
